Skip to content

FirefoxMV2 : 修正部份主要项目#1331

Merged
CodFrm merged 23 commits intoscriptscat:release/mv2from
cyfung1031:fix/mv2/update-20260405
Apr 22, 2026
Merged

FirefoxMV2 : 修正部份主要项目#1331
CodFrm merged 23 commits intoscriptscat:release/mv2from
cyfung1031:fix/mv2/update-20260405

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

@cyfung1031 cyfung1031 commented Apr 5, 2026

Checklist / 检查清单

  • Fixes mentioned issues / 修复已提及的问题
  • Code reviewed by human / 代码通过人工检查
  • Changes tested / 已完成测试

Description / 描述

由于现时的MV3版本在Firefox 无法支持后台脚本,所以只好继续维护MV2版

这个PR的改动是基于现时 1.3 及 1.4 版

npm -> pnpm

  • workflow files, markdown 等也改成 pnpm
  • jest.config.js 修正
  • npm package lock 暂时保留

npm库版本

  • 跟随 1.3 版提升
  • 解决部份 vulnerability

ts.worker.js

  • 跟随 1.4 版使用 ZipExecutionPlugin (webpack版), 不需要做多次网络要求再合并
  • pack.js 退回原本

typescript & tsconfig

  • typescript 升级至常用的 4.9
  • tsconfig 由 es2021 提升至 es2022 以支持 Object.hasOwn

eslint

  • 避免和1.3/1.4 版出现太大差异,lint 不同之处都在 eslintrc.cjs 改了。例如 prefer-destructuring 设为 off
  • 部份禁用理由是为了正常 build,例如 no-unused-vars

tpl (normal, crontab, background) [新脚本范本对齐 chrome 版]

  • 更新至 1.3 版 (包括使用 lazyScriptName )

沙盒 [bug fix]

  • window.parent 修正

cron [syntax 对齐 chrome 版]

  • npm 包升级至 5.0.0-beta.1 (即 1.3 最新版 + child_process 移除): 由于 webpack 无法像 rspack 自行拆除未使用的 child_process,需使用 beta 版
  • cron 的升级是必需,因为旧版本的计时器有bug
  • crontab 业务代码升级至 1.3 版, 支持表达式 once(...)
  • 排程时间显示的 translation.json 跟随修改

Monaco Editor [使用体验对齐 chrome 版]

  • 跟随 1.4 版升级成多国语言
  • 跟随 1.4 版修订了 CodeEditor 等设定

補回 injected.js 的 sourceURL

Screenshots / 截图

@cyfung1031 cyfung1031 linked an issue Apr 5, 2026 that may be closed by this pull request
@cyfung1031 cyfung1031 changed the title FirefoxMV2 简易修正 FirefoxMV2 : 修正部份主要项目 Apr 5, 2026
@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Apr 7, 2026

说实话,不是很想这么大的改动ff mv2了,我怕陷入泥潭

你确定这个改动没有问题,不会影响运行就行吧,我合并发布

@cyfung1031 cyfung1031 marked this pull request as draft April 7, 2026 04:58
@cyfung1031
Copy link
Copy Markdown
Collaborator Author

cyfung1031 commented Apr 7, 2026

你确定这个改动没有问题,不会影响运行就行吧,我合并发布

@CodFrm 應該是沒問題的,不過我再在firefox跑一下吧

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Apr 8, 2026

pnpm和package-lock同时存在了,可以只留pnpm,需要处理一下合并冲突

@cyfung1031 cyfung1031 marked this pull request as ready for review April 11, 2026 03:31
@cyfung1031
Copy link
Copy Markdown
Collaborator Author

cyfung1031 commented Apr 11, 2026

你确定这个改动没有问题,不会影响运行就行吧,我合并发布

可以了
先合并发布吧
有些MV2的UI Bug还存在。不过先这样

@CodFrm #1187 的问题你可以在这加 commit

@cyfung1031
Copy link
Copy Markdown
Collaborator Author

待合并。合并后可以发布 0.16.14

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Apr 14, 2026

待合并。合并后可以发布 0.16.14

非常感谢!我这两天有空试一下

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues maintaining the Firefox MV2 build by aligning it with newer Chrome/MV3-era improvements (tooling, cron behavior, Monaco editor UX) while adding build-time optimizations for worker bundling.

Changes:

  • Migrates tooling from npm to pnpm (scripts/docs/workflows) and updates dependencies.
  • Adds a webpack ZipExecutionPlugin to reduce ts.worker.js size and simplifies packaging.
  • Refactors cron parsing/execution (once(...) support), Monaco editor integration (multi-language + quick-fixes), and reworks various runtime injection/sourcemap behaviors.

Reviewed changes

Copilot reviewed 44 out of 49 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
webpack/webpack.linter.dev.ts Removes unused prod-minifier import in dev linter config.
webpack.config.ts Adds ZipExecutionPlugin to the web worker webpack config.
webpack-plugins/ZipExecutionPlugin.ts New webpack plugin to compress/inline string tables for ts.worker.js.
tsconfig.json Bumps lib target to ES2022.
src/types/scriptcat.d.ts Updates ScriptCat/TM-compatible GM API typings and metadata fields.
src/template/normal.tpl Updates default namespace and adds optional @icon placeholder.
src/template/crontab.tpl Updates default namespace and formatting alignment.
src/template/background.tpl Updates default namespace and formatting alignment.
src/runtime/content/utils.ts Adds sourceMapTo, adjusts style injection typing, and introduces addStyleSheet.
src/runtime/content/sandbox.ts Refactors cron once(...) execution gating and cron parsing via extractCronExpr.
src/runtime/content/inject.ts Switches require-css injection to addStyleSheet and moves external API logic out.
src/runtime/content/external.ts New module for window.external exposure/compat (ScriptCat/Tampermonkey).
src/pkg/utils/utils.ts Adds deferred, sourceMapTo, getISOWeek, and changes tryConnect signature.
src/pkg/utils/utils.test.ts Replaces cron tests with deterministic nextTimeInfo/nextTimeDisplay coverage.
src/pkg/utils/script.ts Uses extractCronExpr for cron validation instead of nextTime.
src/pkg/utils/monaco-editor/utils.ts New helpers for /* global */ insertion and regex escaping.
src/pkg/utils/monaco-editor/utils.test.ts Adds unit tests for new monaco-editor utilities.
src/pkg/utils/monaco-editor/langs.ts Adds multi-language editor prompts and strings.
src/pkg/utils/monaco-editor/index.ts New monaco registration module (worker + hover + code actions + types).
src/pkg/utils/monaco-editor/config.ts New default TS/JS compiler options for Monaco.
src/pkg/utils/monaco-editor.ts Removes legacy monaco registration implementation.
src/pkg/utils/cron.ts Rewrites cron helpers: extractCronExpr, nextTimeInfo, nextTimeDisplay with i18n.
src/pkg/config/config.ts Adds lazyScriptName for auto-renaming new scripts.
src/pages/options/routes/script/ScriptEditor.tsx Refactors editor/hotkeys; auto-fills match/icon; integrates lazyScriptName.
src/pages/options/routes/ScriptList.tsx Uses nextTimeDisplay for scheduled-script tooltip text.
src/pages/options/main.tsx Updates monaco registration import and updates tryConnect error handling.
src/pages/install/main.tsx Updates monaco registration import.
src/pages/install/description.tsx Improves scheduled-script description layout and uses nextTimeDisplay.
src/pages/components/CodeEditor/index.tsx Reworks Monaco editor init + ESLint worker plumbing and editor options.
src/locales/zh-TW/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/zh-CN/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/vi-VN/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/ru-RU/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/ja-JP/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/en-US/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/de-DE/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/locales/ach-UG/translation.json Adds cron i18n keys and updates scheduled-script description keys.
src/content.ts Appends sourceURL for injected script to improve debugging.
pnpm-workspace.yaml Adds pnpm workspace configuration file.
package.json Switches build scripts to pnpm and updates dependencies/tooling versions.
jest.config.js Updates transformIgnorePatterns for pnpm layout.
build/pack.js Removes Firefox ts.worker.js chunk-splitting logic.
CONTRIBUTING.md Updates contributor docs from npm to pnpm commands.
.github/workflows/test.yaml Updates CI to pnpm + Node 22 and newer GitHub Actions versions.
.github/workflows/packageRelease.yml Updates release workflow to pnpm + Node 22.
.github/workflows/build.yaml Updates build workflow to pnpm + Node 22.
.eslintrc.cjs Adjusts lint rules to reduce divergence and ease building.

Comment on lines +83 to +87
onChange(node.editor.getValue() || "");
});
callbackEditor(codeEditor.current.editor);
return () => {};
}, [init]);
callbackEditor(node.editor);
return node.editor.dispose.bind(node.editor);
}, [node?.editor]);
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effect registers editor actions and an onKeyUp handler using hotKeys/script/onChange/callbackEditor, but the dependency array only includes node?.editor. This can lead to stale closures (e.g., hotkey labels/actions not updating) and the cleanup currently disposes the entire editor instance, which can conflict with CodeEditor’s own disposal. Track and dispose the returned IDisposable(s) from addAction/onKeyUp, and include the referenced props in the dependency array (or make them stable via useCallback/useMemo).

Copilot uses AI. Check for mistakes.
Comment on lines +152 to +155
edit.setModel({
original: editor.createModel(diffCode, "javascript"),
modified: editor.createModel(code, "javascript"),
});
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff editor models created via editor.createModel are not disposed in the cleanup. Disposing the editor does not automatically dispose standalone models, so repeated mounts can leak models and memory. Capture the created models and dispose them in the effect cleanup (or use getModel()/dispose appropriately).

Copilot uses AI. Check for mistakes.
Comment on lines +197 to +201
actions.push({
title: `将 '${globalName}' 声明为全局变量 (/* global */)`,
diagnostics: [val],
kind: "quickfix",
edit: { edits: [{ resource: model.uri, textEdit, versionId: undefined }] },
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This quick-fix title is hardcoded in Chinese, but the surrounding UI is now multi-language (multiLang.*). This will show mixed-language UI for non-zh locales. Move this string into the editorLangs entries (or otherwise localize it similarly to the other action titles).

Copilot uses AI. Check for mistakes.
Comment thread src/runtime/content/utils.ts Outdated
@@ -1,5 +1,6 @@
import { type ScriptRunResource } from "@App/app/repo/scripts";
import { has } from "@App/pkg/utils/lodash";
import { sourceMapTo } from "@App/pkg/utils/utils"
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon at the end of the import; this file otherwise uses semicolons consistently, and leaving it out can fail linting/formatting checks.

Copilot uses AI. Check for mistakes.
Comment on lines +298 to +302
const sheet = new CSSStyleSheet();
// it might return as Promise
sheet.replaceSync(css);
// adoptedStyleSheets is FrozenArray so it has to be re-assigned.
document.adoptedStyleSheets = document.adoptedStyleSheets.concat(sheet);
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addStyleSheet uses constructable stylesheets (CSSStyleSheet/replaceSync/adoptedStyleSheets) without any feature detection. In environments where these APIs are unavailable, this will throw at runtime and break @require-css injection. Add a capability check and fall back to the existing <style> injection path when unsupported.

Copilot uses AI. Check for mistakes.
@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Apr 22, 2026

测试下来,暂时没发现什么问题,而且代码和main的也是保持一致的,不太想动copilot说的内容

还是动了,顺便把main的也改了

@CodFrm

This comment was marked as low quality.

CodFrm added a commit to cyfung1031/scriptcat that referenced this pull request Apr 22, 2026
- src/runtime/content/utils.ts: 补回漏掉的分号
- src/runtime/content/utils.ts: addStyleSheet 增加特性检测,旧浏览器
  (无 Constructable Stylesheets / adoptedStyleSheets)回退到 <style> 注入
- src/pkg/utils/monaco-editor: declare-global quickfix 标题改用 multiLang,
  补全 7 种语言的 declareGlobal key(之前硬编码中文)
- src/pages/components/CodeEditor: diff editor 的两个 createModel 在 cleanup
  里显式 dispose,避免反复挂载导致 standalone model 泄漏
- src/pages/options/routes/script/ScriptEditor: 跟踪 addAction/onKeyUp 返回的
  IDisposable 并清理;使用 ref 避免 stale closure;移除对 editor 实例的
  二次 dispose(CodeEditor 已自行管理生命周期)
- src/runtime/content/utils.ts: 补回漏掉的分号
- src/pkg/utils/monaco-editor: declare-global quickfix 标题改用 multiLang,
  补全 7 种语言的 declareGlobal key(之前硬编码中文)
- src/pages/components/CodeEditor: diff editor 的两个 createModel 在 cleanup
  里显式 dispose,避免反复挂载导致 standalone model 泄漏
- src/pages/options/routes/script/ScriptEditor: 跟踪 addAction/onKeyUp 返回的
  IDisposable 并清理;使用 ref 避免 stale closure;移除对 editor 实例的
  二次 dispose(CodeEditor 已自行管理生命周期)
@CodFrm CodFrm force-pushed the fix/mv2/update-20260405 branch from 32badfe to fb11491 Compare April 22, 2026 03:36
@CodFrm CodFrm merged commit 1c04fa1 into scriptscat:release/mv2 Apr 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] 嵌套iframe会接受不到postMessage的消息

3 participants